package com.example.mqspring.rabiitmqbasicleverone.rabbitmq;

import com.example.mqspring.utils.RabbitMqUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

public class MainMetho {

    public static void main(String[] args) {
        String queue = "selfqueue";
        Connection connection=null;
        ProductJson product = new ProductJson();
        connection = RabbitMqUtil.createConnection();
        Channel channel = null;
        try {
            channel = connection.createChannel();
            product.sendMessage(channel, queue);
            Consume consume = new Consume(channel);
//            消费消息,最后一个参数是回调类
            String consumTag = channel.basicConsume(queue, true, consume);
            channel.basicCancel(consumTag);
        } catch (Exception e) {
            System.out.println("异常");
        } finally {
            try {
                channel.close();
                connection.close();
            } catch (Exception e) {
                System.out.println("异常");
            }
        }
    }
}
